package com.gexiaobao.pigeon.ui.dialog

import android.annotation.SuppressLint
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import androidx.appcompat.widget.AppCompatEditText
import androidx.appcompat.widget.AppCompatImageView
import androidx.appcompat.widget.AppCompatTextView
import com.gexiaobao.pigeon.R

/**
 * @author: hxw
 * @date  : 2022/12/8
 * @desc  :
 */
class RxDialogAddDevice(context: Context?) : RxDialog(context!!) {

    private lateinit var sureView: AppCompatTextView
    private lateinit var editCodeView: AppCompatEditText
    private lateinit var ivScanView: AppCompatImageView
    private lateinit var ivCloseView: AppCompatImageView

    init {
        initView()
    }

    @SuppressLint("MissingInflatedId")
    private fun initView() {
        val dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_add_device, null)
        sureView = dialogView.findViewById(R.id.tvSureView)
        editCodeView = dialogView.findViewById(R.id.etDeviceCode)
        ivScanView = dialogView.findViewById(R.id.ivScanDeviceCode)
        ivCloseView = dialogView.findViewById(R.id.iv_dialog_add_device_close)

        ivCloseView.setOnClickListener {
            dismiss()
        }

        setContentView(dialogView)
    }

    fun setSureListener(listener: View.OnClickListener?) {
        sureView.setOnClickListener(listener)
    }

    fun setScanListener(listener: View.OnClickListener?) {
        ivScanView.setOnClickListener(listener)
    }

    fun setCode(code: String) {
        editCodeView.setText(code)
    }

    fun getCode(): String {
        return editCodeView.text.toString().trim()
    }

    fun setSele(length: Int) {
        editCodeView.setSelection(length)
    }

}